package com.cloud.security.controller;

import com.cloud.common.domain.Result;
import com.cloud.entity.AuthBody;
import com.cloud.security.service.ISecurityService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Tag(name = "系统认证管理")
@RestController
@RequestMapping("/security/info")
public class SecurityController {

    @Autowired
    private ISecurityService securityService;

    @Operation(summary = "移除授权信息(退出登录)")
    @GetMapping("/loginOut")
    public Result loginOut() {
        securityService.deleteLoginInfo();
        return Result.success("操作成功");
    }

    @Operation(summary = "获取登录验证码")
    @GetMapping("/inAuth/getCode")
    public Result getCode() {
        return securityService.queryCode();
    }

    @Operation(summary = "刷新授权信息(header传参)")
    @PostMapping("/verifyAuth")
    public Result verifyAuth() {
        securityService.setAuthUserInfo();
        return Result.success("操作成功");
    }

    @Operation(summary = "获取登录信息(header传参)")
    @GetMapping(value = "/getUserToken")
    public Result getUserToken() {
        return securityService.getUserToken();
    }

    @Operation(summary = "校验接口权限(header传参)")
    @RequestMapping(value = "/checkAuthority", method = {RequestMethod.POST, RequestMethod.GET})
    public Result checkAuthority(String permission) {
        return securityService.checkAuthority(permission);
    }

    @Operation(summary = "获取登录信息")
    @RequestMapping(value = "/inAuth/getLoginUser", method = {RequestMethod.POST, RequestMethod.GET})
    public Result getLoginUser(@RequestBody AuthBody authBody) {
        return Result.success("操作成功", securityService.getLoginUser(authBody));
    }

}
